package types

import (
	"cuelang.org/go/cue/ast"
)

type Types interface {
	Value(ref bool) string
	Default() string
}

func Of(expr ast.Expr) Types {
	switch expr.(type) {
	case *ast.Ident: //单类型
		return &Ident{
			vv: expr.(*ast.Ident),
		}
	case *ast.BinaryExpr: //有默认值的简单类型
		return &Binary{
			vv: expr.(*ast.BinaryExpr),
		}
	case *ast.ListLit: //数组类型
		return &List{
			vv: expr.(*ast.ListLit),
		}
	case *ast.StructLit: //map类型
		return &Map{
			vv: expr.(*ast.StructLit),
		}
	case *ast.SelectorExpr: //引用类型
		return &Reference{
			vv: expr.(*ast.SelectorExpr),
		}
	default:
		return &NoOp{
			vv: expr,
		}
	}
}
